﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="AJAX_learning.Default"
	EnableViewState="false" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title></title>
	<script type="text/javascript" language="javascript">
		// <!CDATA[
		function Button1_OnClick() {
			var testSportsCar = new AJAXBook.SportsCar('Porsche', '999', '2005', '6');
			var testImitationSportsCar = new AJAXBook.ImitationSportsCar('Shorspe', '123', '2005');
			ProcessCar(testSportsCar);
			ProcessCar(testImitationSportsCar);
			return false;
		}

		function ProcessCar(theCar) {
			if (AJAXBook.IStickShift.isImplementedBy(theCar)) {
				alert("Current Car: " + theCar.get_MakeandModel() + " This is a good sports car "
						+ " -- I can change gears with a stick shift.");
				theCar.set_CurrentGear(5);
				alert(theCar.get_MakeandModel() + " is now cruising in gear number: " + theCar.get_CurrentGear());
			}
			else {
				alert("Current Car: " + theCar.get_MakeandModel() + " This is an imitation sports car " + " -- it's an automatic with a sleek body.");
			}
		}

		function GetValueButtonOnClick() {
			requestValue = AJAX_learning.CarService.GetCarValue(document.forms.form1.Make.value,
													document.forms.form1.Model.value,
													document.forms.form1.Year.value,
													OnComplete, OnError);

			return false;
		}

		function OnComplete(result) {
			alert("The car is worth s$" + result);
		}
		function OnError(error) {
			alert(error.get_message());
		}

		function ArraySample() {
			//Instantiate a JavaScript array object
			var myArray = [];
			myArray[0] = 'First';
			Array.add(myArray, 'Second');
			var newArray = ['Third', 'Fourth', 'Fifth'];
			//Add the newArray object to the myArray
			Array.addRange(myArray, newArray);
			//Remove the last item from the Array
			Array.removeAt(myArray, 0);
			DisplayArray(myArray);
		}
		function DisplayArray(arr) {
			var i;
			var strArray = '';
			for (i in arr) {
				strArray += (i + ':' + arr[i] + ', ');
			}
			alert(strArray);
		}

		function Sum() {
			requestValue = AJAX_learning.CarService.GetTotal(document.forms.form1.ItemA.value,
															document.forms.form1.ItemB.value,
															OnCompleteSum, OnError);

			return false;

		}

		function OnCompleteSum(arg) {
			var Result = $get("Result");
			//Sys.UI.DomElement.setLocation
			Result.value = arg;
		}

		function repositionPanel() {
			var panel = $get('MovePanel');
			var newX = Number.parseInvariant($get('txtX').value);
			var newY = Number.parseInvariant($get('txtY').value);
			Sys.UI.DomElement.setLocation(panel, newX, newY);
			//Now use getLocation to retrieve the new coordinates
			var newPos = Sys.UI.DomElement.getLocation(panel);
			//			alert(String.format("Moved to: {0}, {1}", newPos.x, newPos.y));
			$removeHandler(Button3, "click", repositionPanel);
		}

		function reloadPage() {
			//window.setTimeout("__doPostBack()", 1000);
			//__doPostBack();
		}

		// ]]>
	</script>
</head>
<body onload="return reloadPage()">
	<%--<body>--%>
	<form id="form1" runat="server">
	<div>
		<asp:ScriptManager ID="ScriptManager1" runat="server">
			<Scripts>
				<asp:ScriptReference Path="~/AJAXBook.js" />
			</Scripts>
			<Services>
				<asp:ServiceReference Path="~/CarService.asmx" />
			</Services>
		</asp:ScriptManager>
	</div>
	<div>
		<asp:TextBox ID="TimeTextBox" runat="server" />
	</div>
	<div>
		<input id="Button1" type="button" value="button" onclick="return Button1_OnClick()" />
	</div>
	<hr />
	<div id="sampel1">
		<div>
			<asp:Label ID="MakeLabel" runat="server" Text="Make: " />
			<%--<input id="Make" type="text" value="Honda" />--%>
			<asp:TextBox ID="Make" runat="server" Text="Honda" />
		</div>
		<div>
			<asp:Label ID="ModelLabel" runat="server" Text="Model: " />
			<%--<input id="Model" type="text" value="Pilot" />--%>
			<asp:TextBox ID="Model" runat="server" Text="Pilot" />
		</div>
		<div>
			<asp:Label ID="YearLabel" runat="server" Text="Year: " />
			<%--<input id="Year" type="text" value="2005" />--%>
			<asp:TextBox ID="Year" runat="server" Text="2005" />
		</div>
		<%--<asp:Button ID="GetValueButton" runat="server" Text="Get Value" OnClick="return GetVuleButtonOnClick()" />--%>
		<input type="button" id="GetValueButton" value="Get Value" onclick="return GetValueButtonOnClick()" />
	</div>
	<hr />
	<div>
		<input id="Button2" type="button" value="Array Sample" onclick="return ArraySample()" />
	</div>
	<hr />
	<div>
		<div>
			<asp:Label ID="ItemALabel" Text="A: " runat="server" />
			<input id="ItemA" type="text" value="0" onkeypress="Sum();" />
			<%--<asp:TextBox ID="ItemA" runat="server" />--%>
		</div>
		<div>
			<asp:Label ID="ItemBLabel" Text="B: " runat="server" />
			<input id="ItemB" type="text" value="0" onkeypress="Sum();" />
			<%--<asp:TextBox ID="ItemB" runat="server" />--%>
		</div>
		<div>
			<asp:Label ID="ResultLabel" Text="Result: " runat="server" />
			<input id="Result" type="text" />
			<%--<asp:TextBox ID="Result" runat="server" />--%>
		</div>
	</div>
	<hr />
	<div id="MovePanel">
		<b>Move me to:</b>
		<br />
		X Coordinate
		<input type="text" id="txtX" />
		<br />
		Y Coordinate
		<input type="text" id="txtY" /><br />
		<input id="Button3" type="button" value="Move" onclick="repositionPanel ()" />
	</div>
	</form>
</body>
</html>
